<% 
  var headContent = {
%>
<!-- //这里包含需要引入的其他css/js文件 -->
<style>
 /*验证：提示信息样式 begin*/
 .am-alert-danger {
    background-color: transparent;
    border-color: transparent;
    color: red;
  }
  .am-alert {
    margin-bottom: 1em;
    padding: .625em;
    background: transparent;
    border: none;
    border-radius: 0;
  }
  /*验证：提示信息样式 end*/
  /*附件上传*/
  .am-progress-xs {
    height: .2rem;
  }
  .am-progress {
    margin-bottom: 0;
  }
</style>
<%};%>
<%layout("/common/_layout.html",{head:headContent}){%>
<div>
  <% include("/admin/waiting_hint.tpl"){}%></div>
<input type="hidden" id="moduleId" name="moduleId" value="${moduleId!0}"/>
<input type="hidden" id="payId" name="payId" value="${payId!0}"/>
<input type="hidden" id="moduleName" name="moduleName" value="${moduleName!''}"/>
<input type="hidden" id="payName" name="payName" value="${payName!''}"/>
<input type="hidden" id="search-type" name="search-type" value="${searchType!}" />
<input type="hidden" id="keywords-website" name="keywords" value='${keywords!""}' />
<div class="am-cf am-padding">
  <div class="am-fl am-cf"> <strong class="am-text-primary am-text-lg" onclick="location.href='${base}/website/payMethods';">系统管理</strong>
    /
    <small>显示配置</small>
     /
    <small>${moduleName}->${payName}</small>
  </div>

</div>
<div class="am-tabs am-margin" data-am-tabs>
  <ul class="am-tabs-nav am-nav am-nav-tabs">
    <li id="li-website"  class="am-active">
      <a href="#tab-website">网点授权</a>
    </li>
  </ul>
  <div class="am-tabs-bd">
   <div class="am-tab-panel am-fade am-in am-active" id="tab-website">
      <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6" style="padding:0px 1.6rem 1.6rem 1rem;margin:0px;">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
              <%if(so.hasPermission("PAY_CONFIG_ADD")) {%>
              <button type="button" class="am-btn am-btn-default" id="add-website-btn">
                <span class="am-icon-plus"></span>
                新增
              </button>
              <%}%>
              <%if(so.hasPermission("PAY_CONFIG_DEL")) {%>
              <button type="button" id="deleteButtonWebsite" disabled="disabled" class="am-btn am-btn-default"  onclick="deleteAllWebsite('${base}/website/deletePayWebsite')">
                <span class="am-icon-trash-o"></span>
                删除
              </button>
              <%}%></div>
          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-input-group am-input-group-sm">
            <input type="text" class="am-form-field" id="keyword-website" value="${keywordWebsite!}" placeholder="按名称搜索">
            <span class="am-input-group-btn">
              <button  id="query-website-btn" class="am-btn am-btn-default" type="button">搜索</button>
            </span>
          </div>
        </div>
      </div>
      <div class="am-g">
        <div class="am-u-sm-12">
          <div class="am-scrollable-horizontal">
            <table class="am-table am-table-striped am-table-hover table-main">
              <thead>
                <tr class="am-text-nowrap">
                  <th class="table-check">
                    <input type="checkbox"  id="allCheckWebsite"/>
                  </th>
                  <th class="table-title">网点id</th>
                  <th class="table-title">名称</th>
                </tr>
              </thead>
              <tbody>
                <%if (!isEmpty(websitePage)) {for(list in websitePage.list!){%>
                <tr>
                  <td>
                    <input type="checkbox" name="idsWebsite" value="${list.pid}"></td>
                  <td >${list.WebsiteId}</td>
                  <td >${list.class_name}</td>
                </tr>
                <%}}%></tbody>
            </table>
          </div>
          <div class="am-cf">
            <%if (!isEmpty(websitePage) && websitePage.list.~size >
            0){%>
            <div class="am-fr">
              <% include("/admin/website_pay_auth_pager.tpl"){}%></div>
            <%}else{%>
            <div class="am-kai">
              <h3>没有找到任何记录!</h3>
            </div>
            <%}%></div>
        </div>
      </div>
    </div>  
  </div>
</div>
<div class="am-margin">
  <button type="button" class="am-btn am-btn-warning am-btn-xs" onclick="location.href='${base}/website/toConfig?moduleId=${moduleId}&moduleName=${moduleName}';">返回上一级</button>
</div>

<!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included -->
<script src="${base}/template/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"></script>
<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
<script src="${base}/template/jQuery-File-Upload/js/jquery.iframe-transport.js"></script>
<!-- The basic File Upload plugin -->
<script src="${base}/template/jQuery-File-Upload/js/jquery.fileupload.js"></script>
<script type="text/javascript" src="${base}/template/lhgdialog/lhgdialog.min.js"></script>
<script type="text/javascript">
    var urlBase = "${base}";
    var keywordsObj = {};
    $(function() {
      console.log('search-type:'+$("#search-type").val());
      
     if($("#search-type").val() == 'website') {
        $("#tab-website").tabs('open', 0);
     }
      
      $('#add-website-btn').dialog({
        content: 'url:${base}/website/queryWebsite'+'?moduleId='+$("#moduleId").val()+'&payId='+$("#payId").val(), 
        title: '网点选择', 
        lock: true,
        skin: "idialog",
        width: 800,
        height: 550,
        data: function (backdata) {
          addPayAuthWebsite(backdata);              
        }
      });
      
      
     $("#query-website-btn").on("click",function(){
        console.log('query-website-btn.click');
        if($("#keyword-website").val()) {
          keywordsObj.keywordWebsite = $("#keyword-website").val();
        }
       
        var keywords = "";
        if(!$.isEmptyObject(keywordsObj)){
          keywords = JSON.stringify(keywordsObj);
        }
        console.log("keywords = "+ keywords);
        $("#keywords-website").val(keywords);
        
        queryWebsite();
        
      }); 

     $("#allCheckWebsite").click(function() {
          $('input[name="idsWebsite"]').prop("checked",this.checked);
          if(this.checked){
            $("#deleteButtonWebsite").prop("disabled", false);
          } else {
            $("#deleteButtonWebsite").prop("disabled", true);
          }
      });
      
      var $websiteSubBox = $("input[name='idsWebsite']");
      $websiteSubBox.click(function(){
        console.log('length:'+$("input[name='idsWebsite']:checked").length);
        console.log('$websiteSubBox.length:' + $websiteSubBox.length);
        
        $("#allCheckWebsite").prop("checked", $websiteSubBox.length == $("input[name='idsWebsite']:checked").length ? true : false);
        
        var $idsCheckedCity = $("[name='idsWebsite']:checked");
        if ($idsCheckedCity.size() > 0) {
          $("#deleteButtonWebsite").prop("disabled", false);
        } else {
          $("#deleteButtonWebsite").prop("disabled", true)
        }
      });
    });   
    
    
   function addPayAuthWebsite(orgids) {
      showWaitingHint("保存配置项，请稍候...");
      
      console.log("orgids:" + orgids);
      
      $.ajax({
          url : urlBase + "/website/payConfig",
          type : 'POST',
          dataType : 'json',
          data :orgids+"&moduleId="+$('#moduleId').val()+"&moduleName="+$('#moduleName').val()+"&payId="+$('#payId').val()+"&payName="+$('#payName').val(),
          cache : false,
          beforeSend : function(data) {
              // $('#orgID').selected('disable');
              // $("#submit-btn").prop("disabled", true);
          }
      }).done(function (result) {
          console.log('done.result:' + result);
          dismissWaitingHint();
          showDialog("操作成功", "", "success", 2000);
          queryWebsite();
      }).fail(function () {
        console.log('fail');
          showDialog("操作失败", "", "error", 2000);
          dismissWaitingHint();
      });
    }

    function showDialog(msgTitle, message, msgType, msgTimer){
      sendMessage({
        title : msgTitle,
        text : message,
        type : msgType,
        timer : msgTimer,
        confirmButtonText : false
      });
    }

   function queryWebsite() {
      var url = urlBase + "/website/toAuth?pageNumberWebsite=1&searchType=website&moduleId="+$('#moduleId').val()+"&moduleName="+$('#moduleName').val()+"&payId="+$('#payId').val()+"&payName="+$('#payName').val();

        if ($("#keywords-website").val().length > 0) {
        url+= "&keywords=" + $("#keywords-website").val();
      }
      console.log("url = "+url);
      document.location.replace(url);
    }

    
     function deleteAllWebsite(url) {
      var $idsCheckedCheck = $("[name='idsWebsite']:checked");
      var $deleteButton = $("#deleteButtonWebsite");// 删除按钮
      var ids = $idsCheckedCheck.serialize();
      if (confirm('您确定要删除吗？') == true) {
        $.ajax({
          url : url,
          data : ids,
          dataType : "json",
          async : false,
          beforeSend : function(data) {
            $deleteButton.prop("disabled", true)
          },
          success : function(data) {
            $deleteButton.prop("disabled", false)
            if (data.status == "success") {
              $idsCheckedCheck.parent().parent().remove();
            }
            sendMessage({
              title : "删除!",
              text : data.message,
              type : data.status,
              timer : 2000,
              showConfirmButton : false
            });
            queryWebsite();
          }
        });
      }
    }
    
  </script>
<%}%>